
PROCESSES=`ps -Af | grep "spiderkit"`

EXISTPROCESS=0
HASKEY=0

if [ ! -d "logs" ]; then
    mkdir logs
fi

for p in $PROCESSES; do
    if [ $p = "./bin/spiderkit" ] ; then
        EXISTPROCESS=1
    fi
    if [ $EXISTPROCESS = 1 ] ; then
        HASKEY=1
        break
    fi
done

if [ $HASKEY = 1 ] ; then
    echo "Control script \"./bin/spiderkit\" has already running, exit!"
    exit 0
fi

rm logs/* -rf
export QWS_CACHE_HOME=/app/.qws/cache/
export XDG_CACHE_HOME=/app/.cache/
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:`pwd`/script/target/lib:$LD_LIBRARY_PATH
nohup ./bin/spiderkit > spiderkit.log 2>&1 &
echo $! > spiderkit.pid
